﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {

            string centro = "66814113";
            string cad_conexion = @"Data Source=10.100.14.59\SQLEXPRESS;Initial Catalog=GENERALITAT_DES;Persist Security Info=False;Pwd=Martes31;User ID=sa;";
                               // "Data Source=10.100.14.59\\SQLEXPRESS;Initial Catalog=GENERALITAT_DES;Persist Security Info=False;Pwd=Martes31;User ID=sa;";

            SqlConnection sqlConnection1 = new SqlConnection(cad_conexion);
            SqlCommand cmd = new SqlCommand();
            SqlDataReader reader;

            
            cmd.CommandText = "SELECT correccion_interna FROM alumnos WHERE SUBSTRING(id_alumno,1,8)='" + centro + "' AND NOT correccion_interna ='';";

            cmd.CommandType = CommandType.Text;
            cmd.Connection = sqlConnection1;

            string examenes_correccion_int = string.Empty;
            try
            {
                sqlConnection1.Open();
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    examenes_correccion_int = examenes_correccion_int + reader.GetString(0) + ",";
                }
                
                sqlConnection1.Close();
            }
            catch (Exception ex1)
            {
                throw new Exception("ERROR EN BASE DE DATOS: " + ex1.Message);
            }

            int num_correc_int = examenes_correccion_int.Split(',').Count()-1;

            Console.WriteLine(examenes_correccion_int);
            Console.WriteLine(num_correc_int);
            Console.Read();
        }
    }
}
